/***** Serendipity Booksellers -- bookCollection.cpp *****/
#include "stdafx.h"

#include <iostream>
#include <iomanip>
#include "bookCollection.h"
#include <algorithm>
#include <sstream>
#include "btree.h"
#include "cashier.h"

// Function Prototypes
string upperString(string);

/*************************************************************************************
 *                       BookCollection::sortByQty                                   *
 *	Recursive Sort by quantity.                                                      *
 *************************************************************************************/
void BookCollection::sortByQty(BookData bookParam[], int number)
{
	if (number <= 1) return;

	// Move the largest to the end
	int largeIndex = 0;
	for (int k = 1; k < number; k++)
		if (bookParam[k].getQty() > bookParam[largeIndex].getQty())
			largeIndex = k;
	swap(bookParam[largeIndex], bookParam[number-1]);

	// Now do the recursive sort
	sortByQty(bookParam, number-1);
}

/*************************************************************************************
 *                  BookCollection::BookCollection                                   *
 *	Constructor opens the file, reads the number of books                            *
 *	from the file, and then reads the books into the book list.                      *
 *************************************************************************************/
BookCollection::BookCollection()
{
	// Open file
	file.open("Serendipity.data", ios::binary|ios::in);

	// Read number of books in file
	if (!file) return;
	size_t numberBooks;
	file.read(reinterpret_cast<char *>(&numberBooks), sizeof(numberBooks));

	// Read the books into the in-memory list of books
	for (unsigned int k = 0; k < numberBooks; k++)
	{
		BookData b;
		b.load(file);
		bookList.push_back(b);
	}
	file.close();
}

/*************************************************************************************
 *                   BookCollection::~BookCollection                                 *
 *	Destructor truncates the file, then writes the number of books                   *
 *	to the file, and then writes the book to the file.                               *
 *************************************************************************************/
BookCollection::~BookCollection()
{
	// Count actual number of books
	size_t numberBooks = bookList.size();

	// Open the file for writing
	file.clear();
	file.open("Serendipity.data", ios::binary|ios::out);
	if (!file)
	{
		cout << "Could not open the data file.";
		exit(1);
	}

	// Write the number of books to the file
	file.write(reinterpret_cast<char *>(&numberBooks), sizeof(numberBooks));

	// Seriliaze
	list<BookData>::iterator iter = bookList.begin();
	for ( ; iter != bookList.end(); iter++)
		iter->store(file);

	// Done
	file.close();
}

/*************************************************************************************
 *                      BookCollection::lookupIsbn                                   *
 *	This function looks up a book using its ISBN number.                             *
 *	It returns end iterator if there is no such book, otherwise it returns the       *
 *	iterator to the BookData object in the array that has that ISBN number.          *
 *************************************************************************************/
list<BookData>::iterator BookCollection::lookupIsbn(string isbn)
{
	list<BookData>::iterator iter = bookList.begin();
	for (; iter != bookList.end(); iter++)
	{
		if (upperString(iter->getIsbn()) == upperString(isbn))
			return iter;
	}
	return iter;
}

/*************************************************************************************
 *                      BookCollection::displayIsbn                                  *
 *	This displays valid isbn numbers so the user knows which titles are available.   *
 *************************************************************************************/
void BookCollection::displayIsbn()
{
	list<BookData>::iterator iter = bookList.begin();
	for (; iter != bookList.end(); iter++)
	{
		cout << iter->getIsbn() << '\t';
	}
}

/*************************************************************************************
 *                       BookCollection::booksAvailable                              *
 *	This check to see if there are any books available for sale.                     *
 *************************************************************************************/
bool BookCollection::booksAvailable()
{
	return !bookList.empty();
}

/*************************************************************************************
 *                           lookUpBook                                              *
 *	Called by: invMenu()                                                             *
 *	Locates and displays books that match a title entered by the user.               *
 *************************************************************************************/
void BookCollection::lookUpBook()
{
	string desiredTitle;

	cout << "\n\n\n\n";
	cout << "	****************************************\n"
		 << "	*           Look Up Book               *\n"
		 << "	****************************************\n\n";

	cout << "Desired title: ";
	cin.ignore(10, '\n');
	getline(cin, desiredTitle);

	// The vector found will hold indices of all matching books
	vector<list<BookData>::iterator> found;
	match(desiredTitle, found);
	if (found.size() > 0)
		displayBooks(found);
	else
	{
		// Try for partial matches
		partialMatch(desiredTitle, found);
		if (found.size() == 0)
		{
			cout << "No matching books found.\n";
			return;
		}
		else
		{
			displayBooks(found);
			if (found.size() > 10)
				cout << "Too many books match the search criteria.\n";
		}
	}
}

/*************************************************************************************
 *                            BookCollection::match                                  *
 *	Returns a vector of all iterators to books that match the given title.           *
 *************************************************************************************/
void BookCollection::match(string title, vector<list<BookData>::iterator>&found)
{
	title = upperString(title);
	list<BookData>::iterator iter = bookList.begin();
	for (; iter != bookList.end(); iter++)
	{
		if (title == upperString(iter->getTitle()))
			found.push_back(iter);
	}
}

/*************************************************************************************
 *                         BookCollection::partialMatch                              *
 *	Returns a vector of iterators to books whose titles partially match the given    *
 *	partial title.                                                                   *
 *************************************************************************************/
void BookCollection::partialMatch(string partialTitle, vector<list<BookData>::iterator> &found)
{
	partialTitle = upperString(partialTitle);
	list<BookData>::iterator iter = bookList.begin();
	for ( ; iter != bookList.end(); iter++)
	{
		string bookTitle = upperString(iter->getTitle());
		if (bookTitle.find(partialTitle) < bookTitle.length())
		{
			found.push_back(iter);
		}
	}
}

/*************************************************************************************
 *                           BookCollection::displayBooks                            *
 *	Displays all books iterators to which are stored in a vector b.                  *
 *************************************************************************************/
void BookCollection::displayBooks(vector<list<BookData>::iterator> & b)
{
	vector<list<BookData>::iterator>::iterator iter = b.begin();
	while (iter != b.end())
	{
		(*iter)->bookInfo();
		iter++;
	}
}

/*************************************************************************************
 *                               addBook                                             *
 *	Called by invMenu()                                                              *
 *	Adds a book to the inventory.                                                    *
 *************************************************************************************/
void BookCollection::addBook()
{
	// Get info to add the new book
	string title, isbn, author, publisher, date;
	int quantity;
	double wholesaleCost, retailPrice;

	BookData newBook;

	cout << "\n\n\n\n";
	cout << "	****************************************\n"
		 << "	*             Add Book                 *\n"
		 << "	****************************************\n\n";

	cout << "Book Title: ";
	cin.ignore(10, '\n');
	getline(cin, title);
	newBook.setTitle(title);

	cout << "	ISBN: ";
	getline(cin, isbn);
	newBook.setIsbn(isbn);

	cout << "	Author: ";
	getline(cin, author);
	newBook.setAuthor(author);

	cout << "	Publisher: ";
	getline(cin, publisher);
	newBook.setPub(publisher);

	cout << "	Data Added (MM-DD-YYYY): ";
	getline(cin, date);
	newBook.setDateAdded(date);

	cout << "	Quantity-On-Hand: ";
	cin >> quantity;
	newBook.setQty(quantity);

	cout << "	Wholesale Cost: ";
	cin >> wholesaleCost;
	newBook.setWholesale(wholesaleCost);

	cout << "	Retail Price: ";
	cin >> retailPrice;
	newBook.setRetail(retailPrice);

	// Add the new book to the list
	bookList.push_front(newBook);
}

/*************************************************************************************
 *                        BookCollection::find                                       *
 *	Return an iterator to a book of the desired title or the end of list iterator    *
 *************************************************************************************/
list<BookData>::iterator BookCollection::find(string desiredTitle)
{
	desiredTitle = upperString(desiredTitle);
	list<BookData>::iterator iter = bookList.begin();
	while (iter != bookList.end())
	{
		string title = upperString(iter->getTitle());
		if (title == desiredTitle)
			return iter;
		else
			iter++;
	}
	return iter;
}

/***** Miscellaneous Subfunctions *****/

/*************************************************************************************
 *                               upperString                                         *
 *	Called by any function comparing 2 strings.                                      *
 *	Uppercases each character in a copy of the string passed to it and returns the   *
 *	uppercased copy. By calling this function for each of two strings before         *
 *	comparing them, the comparison can be made without regard to case. Since only    *
 *	copies of the strings are changed and compared, the original strings are not     *
 *	altered.                                                                         *
 *************************************************************************************/
string upperString(string s)
{
	for (unsigned int pos = 0; pos < s.length(); pos++)
	{
		s[pos] = toupper(s[pos]);
	}
	return s;
}

/*************************************************************************************
 *                               removeBook                                          *
 *	Called by invMenu()                                                              *
 *	Removes a book from the inventory.                                               *
 *************************************************************************************/
void BookCollection::deleteBook()
{
	// Get info to remove the book
	string desiredTitle;
	char answer;

	cout << "\n\n\n\n";
	cout << "	****************************************\n"
		 << "	*             Remove Book              *\n"
		 << "	****************************************\n\n";

	cout << "Enter the title of the book you wish to be deleted: ";
	cin.ignore(10, '\n');
	getline(cin, desiredTitle);

	vector<list<BookData>::iterator> found;
	match(desiredTitle, found);
	if (found.size() == 1)
	{
		displayBooks(found);
		cout << "Are you sure you want to remove the above book (Y or N): ";
		cin >> answer;
		if((answer == 'Y') || (answer == 'y'))
		{
			BookData removeBook;
			vector<list<BookData>::iterator>::iterator iter = found.begin();
			removeBook = (*iter)->bookReturn();
			list<BookData>::iterator iters = bookList.begin();
			for (; iters != bookList.end(); iters++)
			{
				if (removeBook.getTitle() == iters->getTitle())
				{
					bookList.erase(iters);
					break;
				}
			}
		}
	}
	else
	{
		if (found.size() == 0)
		{
			cout << "No matching books found.\n";
			return;
		}
		else
		{
			cout << "Too many books match the criteria. Please refine the search title.\n";
		}
	}
}

/**
 * Edit Book
 * void BookCollection::editBook()
 *
 * Allows the user to edit data about a given book in the system.
 */
void BookCollection::editBook() {

	// Get info to remove the book
	string desiredTitle;
	char answer = ' ';
  bool menuActive = true;

	cout << "\n\n\n\n";
	cout << "	****************************************\n"
		 << "	*             Edit  Book               *\n"
		 << "	****************************************\n\n";

  do {

  	cout << "Enter the title of the book you wish to edit: ";
	  cin.ignore(10, '\n');
	  getline(cin, desiredTitle);

	  vector<list<BookData>::iterator> found;
	  match(desiredTitle, found);

	  if (found.size() == 1)
	  {

		  displayBooks(found);
		  cout << "Would you like to edit this book? (Y or N): ";
		  cin >> answer;
		  if((answer == 'Y') || (answer == 'y'))
		  {

  		   vector<list<BookData>::iterator>::iterator iter = found.begin();
         list<BookData>::iterator masterListIter = bookList.begin(); 
         int masterListSize = bookList.size();
          
         BookData *book = new BookData();
         for (int i = 0 ; i < bookList.size() ; i++) {
 
           book = &(*masterListIter); 
           if (book->getIsbn() == (*iter)->getIsbn()) {

             menuActive = false;

             bool moreChanges = false;
             bool editFields = true;
             char change;

             // Allow user to make more changes
             do {

               if (editFields) {
          
                 editBookFields(*book);
               }

               cout << "\n\nWould you like to make additional changes? (Y or N)";
               cin  >> change;

               if (change == 'Y' || change == 'y') {

               moreChanges = true;
               editFields = true;
             }

             else if (change == 'N' || change == 'n') {

               moreChanges = false;
               editFields = false;
             }           
           
             else {

               cout << "\n\nPlease enter 'Y' or 'N'\n\n";
               moreChanges = true;
               editFields = false;
             }
           } while (moreChanges);
         }                    
       } 
      }
    
      else if ((answer == 'q' || answer == 'Q')) {
      
        menuActive = true;
      } 
    }
    else {

      char searchAgain = 'n';
      cout << "Search returned no results.  Search again?";
      cin  >> searchAgain; 
      if (searchAgain == 'n' || searchAgain == 'N') {

        return;
      }

    }
  } while (menuActive == true);       

  return;
}

/**
 * Edit Book Fields
 * void editBookFields(BookData book)
 *
 * @param book
 *   This is the book data to be edited.
 */
void BookCollection::editBookFields(BookData &book) {

  int selection = 0;

  cout << "\n\n";

  selection = bookFieldMenu(book);

  cout << "\n\n";

  switch (selection) {

    case (0): { // Quit

      return;
    }

    case (1): { // edit ISBN
 
      string ISBN;

      cout << "Current ISBN:  " << book.getIsbn() << endl;
      cout << "Enter new ISBN: ";
      cin  >> ISBN;

      book.setIsbn(ISBN);
      break;
    }

    case (2): { // edit Title

      string title;

      cout << "Current Title: " << book.getTitle() << endl;
      cout << "Enter new Title: ";
      //cin  >> title;
      cin.ignore(10, '\n');
      getline(cin, title);

      book.setTitle(title);
      break;
    }

    case (3): {  // edit Author

      string author;

      cout << "Current Author: " << book.getAuthor() << endl;
      cout << "Enter new Author: ";
      //cin  >> author;
      cin.ignore(10, '\n');
      getline(cin, author);

      book.setAuthor(author);
      break;
    }

    case (4): { // edit Publisher

      string publisher;

      cout << "Current Publisher: " << book.getPub() << endl;
      cout << "Enter new Publisher: ";
      //cin  >> publisher;
      cin.ignore(10, '\n');
      getline(cin, publisher);

      book.setPub(publisher);
      break;
    }

    case (5): { // edit Quantity on Hand

      int qtyOnHand;

      cout << "Current Quantity on Hand: " << book.getQty() << endl;
      cout << "Enter new Quantity on Hand: ";
      cin  >> qtyOnHand;

      book.setQty(qtyOnHand);
      break;
    }

    case (6): { // edit Wholesale Cost
  
      double cost;

      cout << fixed << showpoint << setprecision(2);

      cout << "Current Wholesale Cost: $" << book.getWholesale() << endl;
      cout << "Enter new Wholesale Cost: $";
      cin  >> cost;

      book.setWholesale(cost);
      break;
    }
  
    case (7): {  // edit Retail Cost

      double cost;

      cout << fixed << showpoint << setprecision(2);

      cout << "Current Retail Price: $" << book.getRetail() << endl;
      cout << "Enter new Retail Price: $";
      cin  >> cost;

      book.setRetail(cost);
      break;
    }
  }
  // Confirmation 
  cout << "\n\n";
  cout << "Adjusted Book Data: " << endl;
  book.bookInfo();
  cout << "\n\n";

  return; 
 
} 

int BookCollection::bookFieldMenu(BookData book)	// Provides a field-by-field numerical menu
                                                  // for book data
{
  int selection;
  bool validSelection = true;
  
  do {
	  // Display company name and screen title
	  cout << "\n\n\n	      Book Information\n\n\n";

	  cout << fixed << showpoint << setprecision(2);

	  // Display information items
    cout << "1	ISBN:			" << book.getIsbn() << endl;
    cout << "2	Title:			" << book.getTitle() << endl;
    cout << "3	Author:			" << book.getAuthor() << endl;
    cout << "4	Publisher:		" << book.getPub() << endl;
    cout << "5	Qty on Hand:		" << book.getQty() << endl;
    cout << "6	Wholesale Cost:		" << book.getWholesale() << endl;
    cout << "7	Retail Price:		" << book.getRetail() << endl;
    cout << "0  Quit" << endl << endl; 
      
    cout << "Make a selection: ";
    cin  >> selection;

    if (selection < 0 || selection > 7) {

      cout << "\n\n Please make a valid selection";
      validSelection = false;
    }
    else {
      
      validSelection = true;
    }
  }  while (validSelection == false);

  return selection;
}

/*************************************************************************************
 *                               repListing                                          *
 *	Called by reports()                                                              *
 *	Lists records of all books in the inventory                                      *
 *************************************************************************************/
void BookCollection::repListing()
{
	cout << "\nListing of current inventory:\n";
	cout << "_______________________________\n\n";

	int screenControl = 0;
	list<BookData>::iterator p = bookList.begin();
	for (; p != bookList.end(); p++)
	{
		cout << "Title:			" << p->getTitle() << endl;
		cout << "ISBN:			" << p->getIsbn() << endl;
		cout << "Author:			" << p->getAuthor() << endl;
		cout << "Publisher:		" << p->getPub() << endl;
		cout << "Date Added:		" << p->getDateAdded() << endl;
		cout << "Qty on Hand:		" << p->getQty() << endl;
		cout << "Wholesale Cost:		$" << p->getWholesale() << endl;
		cout << "Retail Price:		$" << p->getRetail() << endl;
		cout << endl << endl;
		screenControl++;
		if (screenControl == 2)
		{
			system("pause");
			screenControl = 0;
		}
	}
}

/*************************************************************************************
 *                               ConvertDate                                         *
 *	This function converts a string in the form mm/dd/yyyy                           *
 *	or mm-dd-yyyy into three numbers. It is called by compareByAge                   *
 *  It will terminate the program if it runs into a bad date format.                 *
 *************************************************************************************/
void convertDate(string date, int &month, int &day, int &year)
{
	//Convert the data in the string date to a c-string and then
	//make and input stream out of it so we can read numbers from it.
	istringstream datestream(date.data());
	char ch; //Use to read the separation characters / or -

	datestream >> month; datestream >> ch;
	if (ch != '/' && ch != '-')
	{
		cout << "Error in date format: program will terminate.";
		exit(1);
	}
	datestream >> day; datestream >> ch;
	if (ch != '/' && ch != '-')
	{
		cout << "Error in date format: program will terminate.";
		exit(1);
	}
	datestream >> year;
}

/*************************************************************************************
 *                               CompareByAge                                        *
 *	This is used to compare books in sorting by wholesale cost.                      *
 *	Called by repCost                                                                *
 *  Dates are assumed to be in the format mm/dd/yyyy                                 *
 *  It needs to call ConvertDate.                                                    *
 *************************************************************************************/
bool compareByAge(BookData x1, BookData x2)
{
	string date1 = x1.getDateAdded();
	string date2 = x2.getDateAdded();
	int year1, year2;
	int month1, month2;
	int day1, day2;
	convertDate(date1, month1, day1, year1);
	convertDate(date2, month2, day2, year2);
	if (year1 != year2) return year1 < year2;
	if (month1 != month2) return month1 < month2;
	return day1 < day2;
}

/*************************************************************************************
 *                               repAge                                              *
 *	Called by reports()                                                              *
 *	Reports book information based ono the date an                                   *
 *  item was added to the inventory                                                  *
 *************************************************************************************/
void BookCollection::repAge()
{
	if (!booksAvailable())
	{
		cout << "\nThere are currently no books in the inventory." << endl;
		return;
	}
	cout << "Inventory By Date Added\n";
	cout << "________________________\n\n";
	size_t numberOfBooks = bookList.size();
	BookData *book1 = new BookData[numberOfBooks]; //Use as temporary for sorting

	list<BookData>::iterator iter = bookList.begin();
	int k = 0;
	while (iter != bookList.end())
	{
		book1[k] = *iter;
		k++; iter++;
	}

	//Sort the book array in increasing order using STL sort
	sort(book1, book1 + numberOfBooks, compareByAge);

	//Put out the report in increasing order by age
	int screenControl = 0;
	for (int j=numberOfBooks; j > 0; j--)
	{
		BookData *p = &book1[j-1];
		cout << "Title:		" << p->getTitle() << endl;
		cout << "ISBN:		" << p->getIsbn() << endl;
		cout << "Date Added:	" << p->getDateAdded() << endl;
		cout << endl << endl;
		screenControl++;
		if (screenControl == 6)
		{
			system("pause");
			screenControl = 0;
		}
	}
	system("pause");
}

/*************************************************************************************
 *                               CompareByCost                                       *
 *	This is used to compare books in sorting by cost.                                *
 *	Called by repCost                                                                *
 *************************************************************************************/
bool compareByCost(BookData x1, BookData x2)
{
	double whole1 = x1.getWholesale();
	double whole2 = x2.getWholesale();
	if (whole1 != whole2) return whole1 > whole2;
	else return whole1 < whole2;
}

/*************************************************************************************
 *                               CompareByQty                                        *
 *	This is used to compare books in sorting by Qty High to low.                     *
 *	Called by repCost                                                                *
 *************************************************************************************/
bool compareByQty(BookData x1, BookData x2)
{
	int whole1 = x1.getQty();
	int whole2 = x2.getQty();
	if (whole1 != whole2) return whole1 < whole2;
	else return whole1 > whole2;
}

/*************************************************************************************
 *                               repCost                                             *
 *	Called by reports()                                                              *
 *	Reports book information based on the wholesale price                            *
 *************************************************************************************/
void BookCollection::repCost()
{
	if (!booksAvailable())
	{
		cout << "\nThere are currently no books in the inventory." << endl;
		return;
	}
	cout << "Report on Wholesale Cost\n";
	cout << "_________________________\n\n";
	size_t numberOfBooks = bookList.size();
	BookData *book1 = new BookData[numberOfBooks]; //Use as temporary for sorting

	list<BookData>::iterator iter = bookList.begin();
	int k = 0;
	while (iter != bookList.end())
	{
		book1[k] = *iter;
		k++; iter++;
	}

	sort(book1, book1 + numberOfBooks, compareByCost);
	double total = 0;
	int screenControl = 0;
	for (int j=numberOfBooks; j > 0; j--)
	{
		BookData *p = &book1[j-1];
		cout << "Title:			" << p->getTitle() << endl;
		cout << "ISBN:			" << p->getIsbn() << endl;
		cout << "Author:			" << p->getAuthor() << endl;
		cout << "Publisher:		" << p->getPub() << endl;
		cout << "Date Added:		" << p->getDateAdded() << endl;
		cout << "Qty on Hand:		" << p->getQty() << endl;
		cout << "Wholesale Cost:		$" << p->getWholesale() << endl;
		cout << "Retail Price:		$" << p->getRetail() << endl;
		cout << endl << endl;
		screenControl++;
		if (screenControl == 2)
		{
			system("pause");
			screenControl = 0;
		}
	}
	system("pause");
	cout << endl << endl;
}

/*************************************************************************************
 *                               repWholesale                                        *
 *	Called by reports()                                                              *
 *	Reports book information based on the wholesale price                            *
 *************************************************************************************/
void BookCollection::repWholesale()
{
	if (!booksAvailable())
	{
		cout << "\nThere are currently no books in the inventory." << endl;
		return;
	}
	cout << "Wholesale Report\n";
	cout << "___________________\n\n";
	size_t numberOfBooks = bookList.size();
	BookData *book1 = new BookData[numberOfBooks]; //Use as temporary for sorting

	list<BookData>::iterator iter = bookList.begin();
	int k = 0;
	while (iter != bookList.end())
	{
		book1[k] = *iter;
		k++; iter++;
	}

	double total = 0;
	int screenControl = 0;
	for (int j=numberOfBooks; j > 0; j--)
	{
		BookData *p = &book1[j-1];
		cout << "Title:		" << p->getTitle() << endl;
		cout << "ISBN:		" << p->getIsbn() << endl;
		cout << "Quantity:	" << p->getQty() << endl;
		cout << "Wholesale:	$" << p->getWholesale() << endl;
		total += p->getQty() * p->getWholesale();
		cout << endl << endl;
		screenControl++;
		if (screenControl == 6)
		{
			system("pause");
			screenControl = 0;
		}
	}
	cout << "Total Wholesale value of inventory is $" << total << endl;
	system("pause");
	cout << endl << endl;
}

/*************************************************************************************
 *                               repRetail                                           *
 *	Called by reports()                                                              *
 *	Reports book information based on the wholesale price                            *
 *************************************************************************************/
void BookCollection::repRetail()
{
	if (!booksAvailable())
	{
		cout << "\nThere are currently no books in the inventory." << endl;
		return;
	}
	cout << "Wholesale Report\n";
	cout << "___________________\n\n";
	size_t numberOfBooks = bookList.size();
	BookData *book1 = new BookData[numberOfBooks]; //Use as temporary for sorting

	list<BookData>::iterator iter = bookList.begin();
	int k = 0;
	while (iter != bookList.end())
	{
		book1[k] = *iter;
		k++; iter++;
	}

	double total = 0;
	int screenControl = 0;
	for (int j=numberOfBooks; j > 0; j--)
	{
		BookData *p = &book1[j-1];
		cout << "Title:		" << p->getTitle() << endl;
		cout << "ISBN:		" << p->getIsbn() << endl;
		cout << "Quantity:	" << p->getQty() << endl;
		cout << "Retail:		$" << p->getRetail() << endl;
		total += p->getQty() * p->getRetail();
		cout << endl << endl;
		screenControl++;
		if (screenControl == 6)
		{
			system("pause");
			screenControl = 0;
		}
	}
	cout << "Total Retail value of inventory is $" << total << endl;
	system("pause");
	cout << endl << endl;
}

/*************************************************************************************
 *                               repQty                                              *
 *	Called by reports()                                                              *
 *	Reports book information based on the Qty in stock                               *
 *************************************************************************************/
void BookCollection::repQty()
{
	if (!booksAvailable())
	{
		cout << "\nThere are currently no books in the inventory." << endl;
		return;
	}
	cout << "Report on Quantity\n";
	cout << "_________________________\n\n";
	size_t numberOfBooks = bookList.size();
	BookData *book1 = new BookData[numberOfBooks]; //Use as temporary for sorting

	list<BookData>::iterator iter = bookList.begin();
	int k = 0;
	while (iter != bookList.end())
	{
		book1[k] = *iter;
		k++; iter++;
	}

	sort(book1, book1 + numberOfBooks, compareByQty);
	double total = 0;
	int screenControl = 0;
	for (int j=numberOfBooks; j > 0; j--)
	{
		BookData *p = &book1[j-1];
		cout << "Title:		" << p->getTitle() << endl;
		cout << "ISBN:		" << p->getIsbn() << endl;
		cout << "Qty on Hand:	" << p->getQty() << endl;
		cout << endl << endl;
		screenControl++;
		if (screenControl == 6)
		{
			system("pause");
			screenControl = 0;
		}
	}
	system("pause");
	cout << endl << endl;
}